<template>
  <div class="search">
    <a-descriptions bordered size='small' :column='3'>
      <a-descriptions-item label='单号'>
        {{ orderInfo.orderNo }}
      </a-descriptions-item>
      <a-descriptions-item label='制单人'>
        {{ orderInfo.nickName }}
      </a-descriptions-item>
      <a-descriptions-item label='发货日期'>
        {{ orderInfo.sendDate }}
      </a-descriptions-item>
      <a-descriptions-item label='订单日期'>
        {{ orderInfo.createTime }}
      </a-descriptions-item>
      <a-descriptions-item label='部门'>
        {{ orderInfo.deptName }}
      </a-descriptions-item>
      <a-descriptions-item label='业务员'>
        {{ orderInfo.saleManName }}-{{ orderInfo.linkTel }}
      </a-descriptions-item>
      <a-descriptions-item label='供货方'>
        {{ orderInfo.supplierName }}
      </a-descriptions-item>
      <a-descriptions-item label='购货方'>
        {{ orderInfo.customName }}
      </a-descriptions-item>

      <a-descriptions-item label='供方资信'>
        <a-tag color='#2db7f5' v-if='orderInfo.supplierBondType==0'>不垫付</a-tag>
        <a-tag color='purple' v-if='orderInfo.supplierBondType==1'>底价</a-tag>
        <a-tag color='purple' v-if='orderInfo.supplierBondType==2'>底价+税金</a-tag>
        <a-tag color='purple' v-if='orderInfo.supplierBondType==3'>税金</a-tag>
        <a-tag color='purple' v-if='orderInfo.supplierBondType==6'>底价/2+税金</a-tag>
        <a-tag color='purple' v-if='orderInfo.supplierBondType==5'>全额垫付</a-tag>
        <a-tag color='purple' v-if='orderInfo.supplierBondType==8'>销售金额*费率</a-tag>

      </a-descriptions-item>
      <a-descriptions-item label='购方资信'>
        <a-tag color='#2db7f5' v-if='orderInfo.customBondType==0'>全款</a-tag>
        <a-tag color='purple' v-if='orderInfo.customBondType==1'>底价</a-tag>
        <a-tag color='purple' v-if='orderInfo.customBondType==2'>底价+税金</a-tag>
        <a-tag color='purple' v-if='orderInfo.customBondType==6'>底价/2+税金</a-tag>
        <a-tag color='purple' v-if='orderInfo.customBondType==3'>税金</a-tag>
        <a-tag color='purple' v-if='orderInfo.customBondType==5'>全额资信</a-tag>
        <a-tag color='purple' v-if='orderInfo.customBondType==7'>预付款</a-tag>
      </a-descriptions-item>

      <a-descriptions-item label='订单状态'>
        <a-tag color='#87d068' v-if='orderInfo.orderState==0'>未提交</a-tag>
        <a-tag color='#87d068' v-if='orderInfo.orderState==1'>{{ orderInfo.taskName }}</a-tag>
        <a-tag color='#f50' v-if='orderInfo.orderState==2'>已审批</a-tag>
      </a-descriptions-item>

      <a-descriptions-item label='收款金额'>
        {{ orderInfo.takeAmount }}
      </a-descriptions-item>
      <a-descriptions-item label='收款账户'>
        {{ orderInfo.bankName }}
      </a-descriptions-item>
      <a-descriptions-item label='收款日期'>
        {{ orderInfo.takeDate }}
      </a-descriptions-item>
      <a-descriptions-item label='备注' >
        {{ orderInfo.remark }}
      </a-descriptions-item>
    </a-descriptions>
    <a-divider orientation='left'>发货信息</a-divider>
    <f-form ref="form" :action="api.bos" :form-key="this.formItem.sendInfoId">
      <f-form-item label="发票金额" name="invoiceAmount" :value="formItem.invoiceAmount"/>
      <f-form-item label="开票日期" type="date" name="invoiceDate" :value="formItem.invoiceDate" :disabled="readOnly"/>
      <f-form-item label="发票号码" name="invoiceNo" :value="formItem.invoiceNo"/>
      <f-form-item label="发票收件地址" type="select" name="customFpId" :value="formItem.customFpId"  :data="api.customAddress.list" valueKey="customAddressId" label-key="userName,address,telephone" :params="params2" v-if="invoiceSendType==2" :dropdown-render="true" @addItem="addItem2"/>
      <f-form-item label="随发票资料" name="invoiceAttachment" :value="formItem.invoiceAttachment"/>
      <f-form-item label="随货资料" name="sendAttachment" :value="formItem.sendAttachment"/>
    </f-form>
    <custom-address-modal ref="addressModal" :addressType="addressType" :custom-id="this.params1.customId" @handleSuccess="handleSuccess"></custom-address-modal>
  </div>
</template>
<script>
  import api from './js/api'
  import SelectCustomModal from '../custom/select_custom_modal'
  import CustomAddressModal from '../custom/custom_address_modal'

  export default {
    name: 'OrderSendInfo',
    props: {},
    data() {
      return {
        refs: this.$refs,
        addressType: 1,
        params1: {
          customId: '',
          addressType: 1
        },
        orderId: '',
        params2: {
          customId: '',
          addressType: 2
        },
        orderInfo:{},
        invoiceSendType:1,
        customFpData: {},
        readOnly: false,
        customShData: {},
        api: Object.assign(api, this.api),
        isAdd: true,//是否是添加模式
        loaded: false,//是否加载完成
        formItem: this.getFormItem()
      }
    },
    methods: {
      getFormItem() {
        return {
          orderId: '',
          remark: '',
          invoiceSendType:1,
          orderImage: []
        }
      },
      addItem(data) {
        this.customShData = data
        this.addressType = 1
        this.$refs['addressModal'].showModal()
      },
      addItem2(data) {
        this.customFpData = data
        this.addressType = 2
        this.$refs['addressModal'].showModal()
      },
      //表单赋值
      setData(data, readOnly) {
        if (readOnly) {
          this.readOnly = readOnly
        }
        this.$refs.form.resetFields()
        this.formItem = this.getFormItem()
        if (data && data.orderId) {
          let params = {
            sendInfoId: data.orderId
          }
          this.orderId = data.orderId
          this.invoiceSendType=data.invoiceSendType
          this.params1.customId = data.customId
          this.refs['form'].getDetails(params, (result) => {
            this.formItem = result
            this.loaded = true
          })
          this.isAdd = false

          let params1 = {
            orderId: data.orderId,
            handlerName: "orderGetHandler"
          }
          this.http.get(this, {
            url: this.api.busOrder.get,
            params: params1,
            success: function(me, data) {
              me.orderInfo = data
            }
          })

        } else {
          this.loaded = true
          this.params1.customId = ''
        }
      },
      //地址自定义添加回调
      handleSuccess(data) {
        if (this.addressType == 1) {
          this.customShData.push(data)
        } else {
          this.customFpData.push(data)
        }
      },
      //提交表单
      handleSubmit(callback) {
        this.$refs.form.submit({ orderId: this.orderId }, callback)
      }
    },
    mounted() {

    },
    created() {
    },
    components: {
      CustomAddressModal,
      SelectCustomModal
    }
  }
</script>

<style scoped lang="less" rel="stylesheet/less">

</style>
